using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Acms.AcmsControls
{
    public class HtmlContentControlEdit : BaseContentControlEdit
    {
        private Telerik.WebControls.RadEditor editor;
        private Literal litDisplay;


        protected override void CreateDisplayControls(PlaceHolder placholder)
        {
            litDisplay = new Literal();
            litDisplay.ID = "litDisplay";
            litDisplay.EnableViewState = true;
            placholder.Controls.Add(litDisplay);
        }

        protected override void CreateEditControls(PlaceHolder placholder)
        {
            editor = new Telerik.WebControls.RadEditor();
            editor.ID = "editor";
            editor.ToolsFile = "~/RadEditorBasicTools.xml";
            editor.ConvertToXhtml = true;
            editor.ShowSubmitCancelButtons = false;
            placholder.Controls.Add(editor);
        }

        private HtmlContentControlProperties properties;
        public HtmlContentControlProperties Properties
        {
            get
            {
                if (properties == null)
                {
                    properties = new HtmlContentControlProperties();
                }
                return properties;
            }
        }

        protected override BaseContentControlProperties GetProperties()
        {
            return Properties;
        }

        protected override void SetProperties(BaseContentControlProperties properties)
        {
            this.properties = (HtmlContentControlProperties)properties;
        }

        protected override void DataBindChildren()
        {
            if (Properties != null)
            {
                editor.Html = Properties.GetHtml();
                litDisplay.Text = Properties.GetHtml();
            }
            base.DataBindChildren();
        }

        protected override void SaveToProperties()
        {
            Properties.SetHtml(editor.Xhtml);
        }

        protected override void DeleteFromProperties()
        {
        }
    }
}
